package com.mowh.multithreading.worker.thread.worker;

import java.util.Random;

/**
 * @author mowh1gd
 * @create 2023/11/23 15:03
 */
public class ClientThread extends Thread {//扮演委托者Client角色
    private final Channel channel;
    private static final Random random = new Random();

    public ClientThread(String name, Channel channel) {
        super(name);
        this.channel = channel;
    }

    @Override
    public void run() {
        try {
            for (int i = 0; true; i++) {
                Request request = new Request(getName(), i);//创建新的请求
                channel.putRequest(request);//把请求放入channel队列中，调用与执行分离
                Thread.sleep(random.nextInt(1000));
            }
        } catch (InterruptedException e) {
        }
    }
}
